package com.yeyouluo.writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SpeakMapper extends Mapper<LongWritable, Text, Text, SpeakBean> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 1. read line
        String line = value.toString();

        // 2. split \t
        String[] fields = line.split("\t");

        // 3. generate SpeakBean
        String deviceId = fields[0];
        String selfDuration = fields[fields.length - 3];
        String thirdPartDuration = fields[fields.length - 2];
        SpeakBean speakBean = new SpeakBean(deviceId, Long.parseLong(selfDuration), Long.parseLong(thirdPartDuration));

        // write context
        context.write(new Text(deviceId), speakBean);
    }
}
